package com.chenyun.common.constants;

public class AuthConstant {
    /**
     * JWT存储权限前缀
     */
    public  static String AUTHORITY_PREFIX = "ROLE_";

    /**
     * JWT存储权限属性
     */
    public  static  String AUTHORITY_CLAIM_NAME = "authorities";

    /**
     * 认证信息Http请求头
     */
    public  static  String JWT_TOKEN_HEADER = "Authorization";

    /**
     * JWT令牌前缀
     */
    public  static String JWT_TOKEN_PREFIX = "Bearer ";

    /**
     * JWT载体key
     */
    public  static String JWT_PAYLOAD_KEY = "payload";

    /**
     * JWT ID 唯一标识
     */
    public  static String JWT_JTI = "jti";

    /**
     * JWT ID 唯一标识
     */
    public  static String JWT_EXP = "exp";



    /**
     * Redis缓存权限规则key
     */
    public  static String RESOURCE_ROLES_KEY = "auth:resourceRoles";

    /**
     * 黑名单token前缀
     */
    public  static  String TOKEN_BLACKLIST_PREFIX = "auth:token:blacklist:";

    public  static   String CLIENT_DETAILS_FIELDS = "client_id, client_secret as client_secret, LOWER(resource_ids) as  resource_ids , scope, "
            + "authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, "
            + "refresh_token_validity, additional_information, autoapprove";

    public  static  String BASE_CLIENT_DETAILS_SQL = "select " + CLIENT_DETAILS_FIELDS + " from oauth_client_details";

    public  static  String FIND_CLIENT_DETAILS_SQL = BASE_CLIENT_DETAILS_SQL + " order by client_id";

    public  static String SELECT_CLIENT_DETAILS_SQL = BASE_CLIENT_DETAILS_SQL + " where client_id = ?";

    /**
     * 密码加密方式
     */
    public  static  String BCRYPT = "{bcrypt}";

    public  static  String JWT_USER_ID_KEY = "id";

    public  static  String JWT_CLIENT_ID_KEY = "client_id";


    /**
     * app端clientid
     */
    public static String AUTH_APPLICATION_APP_ID="lonni-app";
    /**
     * 小程序端 client_id
     */
    public  static  String AUTH_APPLICATION_MINIAPP_ID="lonni-miniapp";
    /**
     * WEB端 client_id
     */
    public  static  String AUTH_APPLICATION_WEB_ID="lonni-web";



    /**
     * 手机验证码key 格式  key: sms-业务类型(SmsCodeType):手机号
     */
    public  static String  AUTH_SMS_CACHE_KEY="sms-{type}:{phone}";


    /**
     * 手机号登录验证码key 格式  key: auth:smslogin:手机号  value:验证码
     */
    public  static String  AUTH_SMS_LOGIN_CACHE_KEY="auth:smslogin:";

    /**
     * 手机验证码过期时间 2分钟
     */
    public static  Long AUTH_SMS_CACHE_KEY_EX=2L;


    /**
     * 图片验证码key,在生成图片验证码时无法知道用户,所以使用uuid作为唯一标识
     * 格式:auth:catcha-uuid value:验证码code
     */
    public  static String AUTH_CATCHA_CACHE_KEY="auth:catcha-";
    /**
     * 验证码防刷的key
     */
    public  static String AUTH_CATCHA_COUNT_CACHE_KEY="auth:catcha-count-";

    /**
     * JWT扩展加密的key值 ,oauth2加解密token需要用到
     */
    public final static String AUTH_SECURITY_JWT_SIGN_KEY="AUTH_SECURITY_JWT_SIGN_KEY";


    /**
     * auth 认证类型
     */
    public  static  class  GrantType{
        //authorization_code,password,client_credentials,implicit,refresh_token,mobile,captcha
        /**密码模式*/
        public final static String PASSWORD_GRANT_TYPE="password";
        /**授权码模式*/
        public final static String AUTHORIZATION_CODE_TYPE="authorization_code";
        /**客户端模式*/
        public final static String CLIENT_CREDENTIALS_TYPE="client_credentials";
        /**隐式模式*/
        public final static String IMPLICIT_TYPE="implicit";
        /**刷新token，任何模式都加入 */
        public final static String REFRESH_TOKEN_TYPE="refresh_token";
        /**手机验证码模式 */
        public final static String MOBILE_CODE_TYPE="mobile";
        /**验证码模式 */
        public final static String CAPTCHA_CODE_TYPE="captcha";
        /**微信模式 */
        public final static String WECHAT_CODE_TYPE="wechat";

    }


    /**
     * head中保存用户信息的key
     */
    public final static String AUTH_USER_HEADER_NAME="sessionUser";


    /**
     * 标识feign请求的请求头标识值
     */
    public final static String FEIGN_HEADER_CLIENT_TYPE_VALUE="feign";


    /**
     * feign请求是否校验权限注解
     * true|false
     */
    public final static String FEIGN_CHECK_ANNOTATION_VALUE="chenyun.satoken.feign.checkAnnotation";

}
